package com.yty.newconsult.service.impl;

import com.yty.newconsult.entity.DailyNews;
import com.yty.newconsult.dao.DailyNewsDao;
import com.yty.newconsult.service.DailyNewsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * (DailyNews)表服务实现类
 *
 * @author makejava
 * @since 2025-04-11 10:34:25
 */
@Service("dailyNewsService")
public class DailyNewsServiceImpl implements DailyNewsService {
    @Resource
    private DailyNewsDao dailyNewsDao;

    @Override
    public List<DailyNews> queryLastestNews(int num) {
        return this.dailyNewsDao.queryLastestNews(num);
    }

    @Override
    public int insertBatch(List<DailyNews> entities) {
        return this.dailyNewsDao.insertBatch(entities);
    }

    @Override
    public List<DailyNews> queryByDate(LocalDate date) {
        return this.dailyNewsDao.queryByDate(date);
    }

    /**
     * 分页查询
     *
     * @param dailyNews 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DailyNews> queryByPage(DailyNews dailyNews, PageRequest pageRequest) {
        long total = this.dailyNewsDao.count(dailyNews);
        return new PageImpl<>(this.dailyNewsDao.queryAllByLimit(dailyNews, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dailyNews 实例对象
     * @return 实例对象
     */
    @Override
    public DailyNews insert(DailyNews dailyNews) {
        this.dailyNewsDao.insert(dailyNews);
        return dailyNews;
    }



    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.dailyNewsDao.deleteById(id) > 0;
    }
}
